<template>
  <div class="hyydxq">
    <!-- 搜索 -->
    <van-search
      shape="round"
      v-model="params.name"
      placeholder="请输入搜索关键词"
      @cancel="params.name = ''"
      @search="onSearch"
    >
      <!-- <template #left-icon>
        <van-icon name="/assets/img/setting.png" />
      </template> -->
    </van-search>
    <!-- 下拉选择 -->
    <van-dropdown-menu active-color="rgba(55, 181, 181, 1)">
      <van-dropdown-item v-model="value1" :options="option1" @change="fenLeiClick" />
      <van-dropdown-item v-model="value2" :options="option2" @change="sortClick" />
    </van-dropdown-menu>
    <!-- 预约信息 -->
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
        <van-cell v-for="(item, key) in list" :key="key" class="approvalItem content" @click="goDetail(item)">
          <div class="cell-content">
            <div class="content-img">
              <img :src="item.photo | imgPaths" alt="" />
            </div>
            <div class="content-right">
              <div>
                <div>{{ item.name }}</div>
                <div style="text-align: center; border-radius: 2px">
                  {{ item.expertTitle && item.expertTitle.title }}
                </div>
              </div>
              <div class="font-style-common">
                <div>擅长领域</div>
                <div>{{ item.typeNames }}</div>
              </div>
              <div class="font-style-common">
                <div>地址</div>
                <div>
                  <span v-if="item.province != null"> {{ item.province.name }}</span>
                  <span v-if="item.city != null"> {{ item.city.name }} </span>
                  <span v-if="item.county != null"> {{ item.county.name }} </span>
                  <span> {{ item.address }} </span>
                </div>
              </div>
              <div class="font-style-common">
                <div style="margin-right: 60px">提问量: {{ item.questionQuantity }}</div>
                <div>回答量: {{ item.replyQuantity }}</div>
              </div>
            </div>
          </div>
        </van-cell>
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
//保养记录
import { getValue, setValue } from '@/utils/auth'
import {
  Col,
  Row,
  Toast,
  Cell,
  CellGroup,
  Popup,
  Picker,
  DatetimePicker,
  PullRefresh,
  CheckboxGroup,
  List,
  Search,
  DropdownMenu,
  DropdownItem,
  Icon
} from 'vant'
import { getHandle, postHandle } from '@/api'
import dayjs from 'dayjs'
export default {
  components: {
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Popup.name]: Popup,
    [Picker.name]: Picker,
    [DatetimePicker.name]: DatetimePicker,
    [PullRefresh.name]: PullRefresh,
    [CheckboxGroup.name]: CheckboxGroup,
    [Toast.name]: Toast,
    [List.name]: List,
    [Search.name]: Search,
    [DropdownMenu.name]: DropdownMenu,
    [DropdownItem.name]: DropdownItem,
    [Col.name]: Col,
    [Row.name]: Row,
    [Icon.name]: Icon
  },
  data() {
    return {
      value1: '',
      value2: '',
      option2: [
        { text: '默认排序', value: '' },
        { text: '职称级别', value: 'expertLevel' }
      ],
      option1: [{ text: '全部分类', value: '' }],
      refreshing: false,
      currentDate: new Date(),
      showPicker1: false,
      list: [],
      loading: false,
      finished: false,
      params: {
        page: 1,
        perPage: 10,
        tenantCode: getValue('tenantCode') || '',
        type: 1,
        name: '',
        types: '',
        orderBy: '',
        orderDir: '',
        auditStatus: 1
        // tenantCode:getValue('tenantCode'),
        // subjectInfoId:getValue('subjectInfoId')
      }
    }
  },
  watch: {},
  created() {
    this.$bridge.register('refresh', data => {
      this.refreshing = true
      this.params.page = 1
      this.getExpertFenLei()
      this.onLoad()
    })
    this.getExpertFenLei()
  },
  mounted() {},
  methods: {
    sortClick(value) {
      this.params.page = 1
      this.list = []
      this.finished = false
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      // 全部分类
      this.params.orderBy = value
      this.params.orderDir = 'desc'
      if (value == '') {
        this.params.orderDir = ''
      }
      this.onLoad()
    },
    // 分类选项点击触发
    fenLeiClick(value) {
      this.params.page = 1
      this.list = []
      this.finished = false
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      // 全部分类
      this.params.types = value
      this.onLoad()
    },
    // 列表搜索过滤
    onSearch() {
      this.params.page = 1
      this.list = []
      this.finished = false

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      this.onLoad()
    },
    // 跳转专家详情页面
    goDetail(item) {
      setValue('expert-detail-obj', JSON.stringify(item))
      this.$bridge.call('expertDetail')
    },
    // 请求专业分类接口
    getExpertFenLei() {
      getHandle('/agri/api/common/businessData/queryList4Amis/?pCode=T000010_BIZ_EXPERT_TYPE').then(res => {
        res.data.options.forEach(item => {
          this.option1.push({
            text: item.label,
            value: item.value
          })
        })
      })
    },
    // 卡片列表
    onRefresh() {
      this.params.page = 1
      this.finished = false

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      this.onLoad()
    },
    // onSearch() {
    //   this.params.page = 1
    //   this.list = []
    //   this.finished = false

    //   // 重新加载数据
    //   // 将 loading 设置为 true，表示处于加载状态
    //   this.loading = true
    //   this.onLoad()
    // },
    onLoad() {
      getHandle('/agri/api/common/subjectInfoExpert/queryListPage', this.params).then(res => {
        if (this.refreshing) {
          this.list = []
          this.refreshing = false
        }
        this.list = this.list.concat(res.data.rows)
        this.loading = false

        if (this.list.length >= res.data.count) {
          this.finished = true
        } else {
          this.params.page = this.params.page + 1
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .van-dropdown-menu__bar {
  border-top: 1px solid #eee;
  box-shadow: none;
}
.cell-content {
  display: flex;
  .content-img {
    width: 54px;
    height: 54px;
    border-radius: 10px;
    overflow: hidden;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .content-right {
    margin-left: 10px;
    & > div {
      display: flex;
      margin-bottom: 5px;
      div {
        margin-right: 10px;
      }
    }
    & > div:last-child {
      margin-bottom: 0;
    }
    & > div:first-child > div:first-child {
      color: #333333;
      font-weight: 500;
      color: #333333;
      font-size: 15px;
    }
    & > div:first-child > div:nth-child(2) {
      width: 84px;
      height: 20px;
      box-sizing: border-box;
      background-color: rgba(55, 181, 181, 0.2);
      padding: 2px 6px;
      font-size: 12px;
      line-height: 20px;
      font-weight: 400;
      color: #37b5b5;
    }
  }
}
.font-style-common {
  font-size: 13px;
  font-weight: 400;
  color: #666666;
}
::v-deep .van-dropdown-menu__title::after {
  border-color: transparent transparent rgba(55, 181, 181, 1) rgba(55, 181, 181, 1);
}
.van-search__content {
  background-color: rgba(247, 247, 247, 1);
}
.ov {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.topCeiling {
  position: fixed;
  top: 0;
  z-index: 1;
}
.topDate {
  width: 80%;
  margin: auto;
  display: flex;
  justify-content: space-between;
  > p {
    font-size: 15px;
    &:first-child {
      width: 40%;
    }
    &:last-child {
      width: 40%;
    }
  }
}
.van-field__control {
  border: 0 !important;
}
.content {
  //   border-bottom: 1px solid #eee;
  padding: 10px 15px;
  width: 355px;
}
</style>
